<template>
  <div>
    <div class="tabs-bar">
      <van-tabs v-model="active">
        <van-tab title="执行中工作"></van-tab>
        <van-tab title="部门工作人员有误"></van-tab>
      </van-tabs>
    </div>
    <div v-show="active === 0">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item,index) in taskList" :key="index" @click="markTask(index,item.id)">
          <span>{{item.KKScode}}</span>
          <br />
          <span>{{item.description}}</span>
          <br />
          <span>{{item.leader}}</span>
        </van-cell>
      </van-list>
    </div>
    <div v-show="active === 1">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="(item,index) in wrongList" :key="index" @click="mendWrong(index,item.id)">
          <span>{{item.KKScode}}</span>
          <br />
          <span>{{item.description}}</span>
          <br />
          <span>{{item.leader}}</span>
        </van-cell>
      </van-list>
    </div>
  </div>
</template>
<script>
import { getTaskList, getWrongList } from "@/api/data";
export default {
  data() {
    return {
      active: 0,
      taskList: [],
      wrongList: [],
      loading: false,
      finished: false
    };
  },
  methods: {
    onLoad() {
      Promise.all([getTaskList(), getWrongList()])
        .then(res => {
          this.loading = false;
          window.taskList = this.taskList = res[0].data;
          window.wrongList = this.wrongList = res[1].data;
          this.finished = true;
          console.log(window.taskList);
          console.log(this.taskList);
        })
        .catch(e => {
          this.$toast("请求错误");
        });
    },
    markTask(index,id) {
      this.$router.push({name:"InProgress",params:{index:index,id:id}});
    },
    mendWrong(index,id) {
      this.$router.push({name:"WrongInfo",params:{index:index,id:id}});
    }
  },
  activated(){
      this.taskList = window.taskList;
      this.wrongList = window.wrongList;   
  },
  deactivated(){
    console.log(window.taskList);
    console.log(window.wrongList);
  }
};
</script>
